﻿var statusID;
var elementsToDisableCurrent;
function confirmDeleteListItem(siteUrl, listTitle, itemId, elementsToDisable)
{
	if (!confirm(L_STSDelConfirm_Text))
		return;
	elementsToDisableCurrent = elementsToDisable;
	EnableElements(elementsToDisableCurrent, false);

	statusID = SP.UI.Notify.addNotification(L_Notification_Delete, true);

	if (siteUrl == null || siteUrl == "")
	{
		siteUrl = "/";
	}

	var clientContext = new SP.ClientContext(siteUrl);
	var oList = clientContext.get_web().get_lists().getByTitle(listTitle);

	this.oListItem = oList.getItemById(itemId);

	oListItem.deleteObject();
	clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded()
{
	SP.UI.Notify.removeNotification(statusID);
	statusID = "";
	RefreshPage(SP.UI.DialogResult.OK)
}

function onQueryFailed(sender, args)
{
	alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
	EnableElements(elementsToDisableCurrent, true);
}

function EnableElements(elements, enable)
{
	if (elements == null)
		return;

	for (var i = 0; i < elementsToDisableCurrent.length; i++)
	{
		var elementCurrent = document.getElementById(elementsToDisableCurrent[i]);
		if (elementCurrent != null)
		{
			elementCurrent.disabled = enable ? "" : "disabled";
		}
	}
}